package product.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import product.utils.DataUtils;

/**
 * Kafaka 生产端
 */
@RestController
public class KafkaController {

	@Autowired
	private KafkaTemplate<String, Object> kafkaTemplate;

	@GetMapping("/message/send")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "message", value = "消息，例如：汪舶译,15530560288,许七,13768181465,1542629976337,9530", dataType = "string", paramType = "path", required = true) })
	@RequestMapping(value = "/send/{message}", method = RequestMethod.GET)
	public boolean send(@PathVariable(value = "message") final String message) {
		kafkaTemplate.send("callLog", message);
		return true;
	}

	@GetMapping("/message/makeDate")
	@RequestMapping(value = "/data", method = RequestMethod.GET)
	public boolean makeDate() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				DataUtils.data();
			}
		}.start();
		return true;
	}

}
